<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>编辑代理商</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
		<script src="__PUBLIC__/static/js/area/area2.js" ></script>
	</head>

	<body>
		<form class="layui-form update_form" >
			<input type="hidden" name="id" value="{$ad.id}" />
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: 115px;">代理城市</label>
				<div class="layui-input-block" style="float: left; margin-right: 10px; margin-left: 0;">
					<select lay-filter="s_province" id="s_province" name="province"></select>
				</div>
				<div class="layui-input-block" style="float: left; margin-right: 0px; margin-left: 0;">
					<select  lay-filter="s_city" id="s_city" name="city">
					</select>
				</div>
			</div>
			{if $Think.session.user_level==1}
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: 115px;">上级省代：</label>
				<div class="layui-input-block update_shurk" style="float: left; margin-right: 20px; margin-left: 0;">
					<select lay-filter="province_id" name="province_id" id="province_id">
						<option bili="" value="">暂时不选</option>
						{volist name="province" id="vo"}
							<option bili="{$vo.oem_bili}" {if $ad.province_id==$vo.id} selected {/if} value="{$vo.id}">(&nbsp;{$vo.province}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;{$vo.user_name}&nbsp;&nbsp;&nbsp;&nbsp;分佣<p>{$vo.oem_bili}</p>%</option>
						{/volist}
					</select>
				</div>
			</div>
			{/if}
			<!------储存当前所选省代的分佣比例--------->
			<p id="bili" style="display:none;"></p>
			<!------储存当前所选省代的分佣比例--------->
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: 115px;">手机号</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="mobile" readonly="readonly" required lay-verify="required" value="{$ad.mobile}" autocomplete="off" class="layui-input"> (作为登录账号)
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: 115px;">市代理姓名</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="user_name" required lay-verify="required" value="{$ad.user_name}" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: 115px;">登录密码</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="password" placeholder="登录密码" required autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: 115px;">市级代理商号</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="cb_no" lay-verify="required" value="{$ad.cb_no}"  placeholder="省市级代理商号" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: 115px;">市级代理商密钥</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="cb_miyao" lay-verify="required" value="{$ad.cb_miyao}"  placeholder="省市级代理商密钥" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: 115px;">新用户赠送鼓励金</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="s_score" lay-verify="required" value="{$ad.s_score}"  placeholder="新用户赠送鼓励金" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
					<label class="layui-form-label" style="width: 115px;">分佣比例</label>
					<div class="layui-input-block update_shurk">
							<input type="number" style="width: 40%;float: left;" id="oem_bili" name="oem_bili" lay-verify="required"  value="{$ad.oem_bili}"  placeholder="分佣占充值比例" autocomplete="off" class="layui-input" >
							<span style="width: 10%;height:38px;line-height:38px;text-align:center;">%</span><p>分佣比例必须小于省代</p>
					</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: 115px;">代理级别</label>
				<div class="layui-input-block">
					<input type="radio" name="oem_level" value="1" title="正式" {if $ad.oem_level == 1}checked{/if}>
					<input type="radio" name="oem_level" value="2" title="自营" {if $ad.oem_level == 2}checked{/if}>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="width: 115px;">状态</label>
				<div class="layui-input-block">
					<input type="radio" name="status" value="1" title="正常" {if $ad.status == 1}checked{/if}>
					<input type="radio" name="status" value="2" title="冻结" {if $ad.status == 2}checked{/if}>
				</div>
			</div>
			<div class="layui-form-item update_btnbox">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit type="button" lay-filter="submit_from">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
		<script>
			//设置代理的省份为默认
			$(function(){
				var str= "{$ad.province}";
				$('#s_province').attr("value",str); 
				$('#s_province').children("option").each(function(){ 
					if ($(this).text() == str) { 
						$(this).attr("selected","selected"); 
						$(this).change(); //产生联动效果
					}else{ 
						if($(this).attr("selected") == "selected") { 
							$(this).removeAttr("selected"); 
						} 
					}
				});
			 });
			//设置代理的市为默认
			$(function(){
				var city= "{$ad.city}";
				$('#s_city').attr("value",city); 
				$('#s_city').children("option").each(function(){ 
					if ($(this).text() == city) { 
						$(this).attr("selected","selected"); 
					}else{ 
						if($(this).attr("selected") == "selected"){ 
							$(this).removeAttr("selected"); 
						} 
					}
				});
			});

			layui.use('form', function() {
				var form = layui.form;
				form.on('select(s_province)', function(data){
					change(1)
				});
				form.on('select(province_id)', function(data){
					//获取所选省代的分润比例
					var bili=$('#province_id').find("option:selected").attr("bili");
                    $("#bili").text(bili);
				});
				form.on('submit(submit_from)', function(data){
					var s=$("#s_province").val();
					var city = $("#s_city").val();
					var bili = $("#bili").text();
					if(s=='0'){
						layer.msg("请选择省份");
						return false;
					}
					if(city=='0'){
						layer.msg("请选择地级市");
						return false;
					}
					if(bili==""){
						if($('#oem_bili').val()>65){
							layer.msg('代理的分佣不能超过65%,请请示上级！', {time:3000});
							return false;
						}
					}else{
						if(($('#oem_bili').val())>parseInt(bili.trim())){
							layer.msg('市代分佣不能超过当前省代的'+bili+'%', {time:3000});
							return false;
						}
					}
					if($('#oem_bili').val()<0){
						layer.msg('请输入正确的分佣比例', {time:1500});
						return false;
					}
					edit_agency();
				    return false;
				});
			});
			_init_area();

			//提交表单
			function edit_agency() {
				$.ajax({
					type: "post",
					url: "{:url('oem/accounts/edit_agency1')}",
					data: $('.layui-form').serialize(), //表单数据
					success: function(data) {
						if(data.code == 200) {
							layer.msg('修改成功', {
								icon: 1,
								time: 1500 //2秒关闭（如果不配置，默认是3秒）
							}, function() {
								window.parent.location.reload();
								var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
								parent.layer.close(index);
							});
						} else {
							layer.msg(data.msg); //保存失败提示
						}
					},
					error: function(data) {
						var a = data;
					}
				});

			}
		</script>
	</body>

</html>